package static_;

public class ChildGame {
    public static void main(String[] args) {
        //定义一个变量1 count，统计有多少小孩加入了游戏
        int count = 0;

        Child child1 = new Child("白骨精");
        child1.join();
//        count++;
        Child.count++;
        Child child2 = new Child("狐狸精");
        child2.join();
//        count++;
        Child.count++;

        Child child3 = new Child("老鼠精");
        child3.join();
//        count++;
        Child.count++;

        System.out.println("共有 " + Child.count + "个小孩加入了游戏...");
    }
}

class Child {
    private String name;
    //定义一个变量 count，是一个类变量(静态变量) static 静态
    //改变量会被 Child 类的所有对象实例共享
    public static int count = 0;

    public Child(String name) {
        this.name = name;
    }

    public void join() {
        System.out.println(name + " 加入了游戏");
    }
}